<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="wf" uri="/augurit-wf"%>
<%@ include file="/common/taglibs.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>发文</title>
  <!-- 引入归档的JS -->
  <%@ include file="../document/documentjs.jsp"%>
</head>

<body topmargin="0">
<form id="main_form" action="/oa-fawen!wfBusSave.action" method="post">
  <!---------------- 隐藏域区域 开始 ----------------->
  <input type="hidden" name="id" value="${id}" />
  <input type="hidden" name="issueDate" value="${issueDate}" />
  <!---------------- 隐藏域区域 结束 ----------------->
  
  
  <wf:hasPriv activities="draft,systematics_leadership_approve"/>
  <table width="600" border="0" cellspacing="2" cellpadding="0" align="center">
  <!---------------- 标题栏 开始 ----------------->
    <tr>
      <td class="red-font-title">广州市城管委用纸</td>
    </tr>
  <!---------------- 标题栏 结束 ----------------->  
  
  <!---------------- 业务表单 开始 ----------------->
    <tr>
      <td align="center"><table width="100%" border="1" cellspacing="0" cellpadding="2" class="red-font-border">
        <tr>
          <td width="12%" height="0"></td>
          <td width="26%"></td>
          <td width="12%"></td>
          <td width="19%"></td>
          <td width="12%"></td>
          <td width="19%"></td>
        </tr>
        <tr bordercolor="#FF0000">
          <td colspan="1" height="70" align="center">文件标题</td>
          <td colspan="5">
            <wf:textarea id="fawen_OaFawen_title" name="title" rows="3" cols="150" cssClass="input-textarea-noborder" style="width:675;overflow:hidden;">${title}</wf:textarea>
          </td>
        </tr>
        <tr bordercolor="#FF0000">
          <td colspan="1" height="35" align="center"><span group="label">编号</span></td>
          <td colspan="1">
            <wf:input type="input" name="code" id="fawen_OaFawen_code" value="${code}" cssClass="input-textarea-noborder" debug="true" style="width:140;" />
            <wf:input type="button" name="AddCode" id="fawen_AddCode" value="编号" cssClass="tpl_ui_btn" onclick="createCode();" />
          </td>
          <td colspan="1" height="35" align="center">秘密等级</td>
          <td colspan="1">
            <select name="secret" style="width:129;" class="input-textarea-noborder">
              <option></option>
              <c:forEach var="secretVar" items="${secretList}">
              <option value="${secretVar.itemName}" ${secret eq secretVar.itemName ? 'selected' : ''}>${secretVar.itemName}</option>
              </c:forEach>
            </select>
          </td>
          <td colspan="1" height="35" align="center">紧急程度</td>
          <td colspan="1">
            <select name="urgency" style="width:129;" class="input-textarea-noborder">
              <option></option>
              <c:forEach var="urgencyVar" items="${urgencyList}">
              <option value="${urgencyVar.itemName}" ${urgency eq urgencyVar.itemName ? 'selected' : ''}>${urgencyVar.itemName}</option>
              </c:forEach>
            </select>
          </td>
        </tr>
        <tr bordercolor="#FF0000">
          <td colspan="3" height="170" valign="top" style="padding:5px 5px 5px 5px;">
            <div style="width:380;height:25;">
              &nbsp;局长签发：
            </div>
            <div style="width:380;height:120;color:black;">
              <wf:opinion activities="chairman_issue" name="opinion_chairman_issue"/>
              <div id="ChairmanCurrentJudgment"></div>
            </div>
            <div style="width:380;text-align:right;">
              <wf:input type="button" name="GenerateChairmanJudgment" id="GenerateChairmanJudgment" value="局长签发意见" cssClass="tpl_ui_btn" onclick="writeJudgment('A');" />
            </div>
          </td>
          <td colspan="3" height="170" valign="top" style="padding:5px 5px 5px 5px;">
            <div style="width:380;height:25;">
              &nbsp;办公室：
            </div>
            <div style="width:380;height:120;color:black;">
              <wf:opinion activities="office_approve,office_confirm,office_confirm_issue" name="opinion_office"/>
              <div id="OfficeCurrentJudgment"></div>
            </div>
            <div style="width:380;text-align:right;">
             <wf:input type="button" name="GenerateOfficeJudgment" id="GenerateOfficeJudgment" value="办公室主任意见" cssClass="tpl_ui_btn" onclick="writeJudgment('B');" />
            </div>
          </td>
        </tr>
        <tr bordercolor="#FF0000">
          <td colspan="3" height="170" valign="top" style="padding:5px 5px 5px 5px;">
            <div style="width:380;height:25;">
              &nbsp;分管局长意见：
            </div>
            <div style="width:380;height:120;color:black;">
              <wf:opinion activities="systematics_leadership_approve" name="opinion_systematics"/>
              <div id="LeadershipCurrentJudgment"></div>
            </div>
            <div style="width:380;text-align:right;">
              <wf:input type="button" name="GenerateSLJudgment" id="GenerateSLJudgment" value="分管局长意见" cssClass="tpl_ui_btn" onclick="writeJudgment('C');" />
            </div>
          </td>
          <td colspan="3" height="170" valign="top" style="padding:5px 5px 5px 5px;">
            <div style="width:380;height:25;">
              &nbsp;业务处：
            </div>
            <div style="width:380;height:120;color:black;">
              <wf:opinion activities="bi_leadership_approve,bi_systematics_leadership_approve,bi_leadership_confirm" name="opinion_bi"/>
              <div id="biCurrentJudgment"></div>
            </div>
            <div style="width:380;text-align:right;">
              <wf:input type="button" name="GenerateBiJudgment" id="GenerateBiJudgment" value="业务处处理意见" cssClass="tpl_ui_btn" onclick="writeJudgment('D');" />
            </div>
          </td>
        </tr>
        <tr bordercolor="#FF0000">
          <td colspan="1" height="35" align="center"><span group="label">主送</span></td>
          <td colspan="5">
            <wf:textarea id="OaFawen_mainSend2" name="mainSend" rows="3" cols="150" cssClass="input-textarea-noborder" style="width:675;overflow:hidden;">${mainSend}</wf:textarea>
            <div style="width:675;text-align:right;">
              <wf:input type="button" name="GenerateMainSend" id="GenerateMainSend" value="添加主送机关" onclick="addMainSendOrgs()" cssClass="tpl_ui_btn" />
            </div>
          </td>
        </tr>
        <tr bordercolor="#FF0000">
          <td colspan="1" height="35" align="center"><span group="label">抄送</span></td>
          <td colspan="5">
            <wf:textarea id="OaFawen_apposeSend2" name="apposeSend" rows="3" cols="150" cssClass="input-textarea-noborder" style="width:675;overflow:hidden;">${apposeSend}</wf:textarea>
            <div style="width:675;text-align:right;">
              <wf:input type="button" name="GenerateApposeSend" id="GenerateApposeSend" value="添加抄送机关" onclick="addApposeSendOrgs()" cssClass="tpl_ui_btn" />
            </div>
          </td>
        </tr>
        <tr bordercolor="#FF0000">
          <td colspan="1" height="35" align="center">拟稿部门</td>
          <td colspan="1">
            <wf:input type="input" name="draftDept" id="OaFawen_draftDept2" value="${draftDept}" cssClass="input-textarea-noborder" style="width:175;" />
          </td>
          <td colspan="1" height="35" align="center"><span group="label">拟稿人</span></td>
          <td colspan="1">
            <wf:input type="input" name="draftPerson" id="OaFawen_draftPerson2" value="${draftPerson}" cssClass="input-textarea-noborder" style="width:129;" />
          </td>
          <td colspan="1" height="35" align="center"><span group="label">核稿人</span></td>
          <td colspan="1">
            <wf:input type="input" name="checkStaff" id="OaFawen_checkStaff2" value="${checkStaff}" cssClass="input-textarea-noborder" style="width:129;" />
          </td>
        </tr>
        <tr bordercolor="#FF0000">
          <td colspan="1" height="35" align="center"><span group="label">校对人</span></td>
          <td colspan="1">
            <wf:input type="input" name="reviewStaff" id="OaFawen_reviewStaff2" value="${reviewStaff}" cssClass="input-textarea-noborder" style="width:175;" />
          </td>
          <td colspan="1" height="35" align="center"><span group="label">印刷人</span></td>
          <td colspan="1">
            <wf:input type="input" name="printStaff" id="OaFawen_printStaff2" value="${printStaff}" cssClass="input-textarea-noborder" style="width:129;" />
          </td>
          <td colspan="1" height="35" align="center"><span group="label">份数</span></td>
          <td colspan="1">
            <wf:input type="input" name="copies" id="OaFawen_copies2" value="${copies}" cssClass="input-textarea-noborder" style="width:129;" />
          </td>
        </tr>
        <tr bordercolor="#FF0000">
          <td colspan="1" height="35" align="center"><span group="label">主题词</span></td>
          <td colspan="5">
            <wf:input type="input" name="keyWord" id="fawen_OaFawen_keyWord" value="${keyWord}" cssClass="input-textarea-noborder" style="width:675;" />
          </td>
        </tr>
      </table></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
    </tr>
  </table>
  <!---------------- 业务表单 结束 -------------------->
</form>

<div id="tpanelDiv" style="text-align:center"></div>

<br/>

</body>
</html>
<!-- script -->
<script>
function writeJudgment(index) {
    var divid = '';
    switch(index) {
        case 'A': divid = 'ChairmanCurrentJudgment'; break;
        case 'B': divid = 'OfficeCurrentJudgment'; break;
        case 'C': divid = 'LeadershipCurrentJudgment'; break;
        case 'D': divid = 'biCurrentJudgment'; break;
    }
    var divobj = document.getElementById(divid);
    if (divid == '' || !divobj) {
        alert('参数错误！');
        return;
    }
    var win = new Ext.ux.wf.WfOpinionWin({
    });
    win.show();
    win.on('complete', function (opinion) {
        divobj.innerHTML = opinion + '<br>&nbsp;&nbsp;${CurrUserName}&nbsp;&nbsp;' + new Date().format('yyyy-MM-dd hh:mm:ss');
    });
}

$(document).ready(function(){
	  $('form[0]').ajaxForm({
	    dataType: 'json', 
	    success: wfBusSaveCallback
	  });
});
	
function wfBusSaveCallback(result){
	var success = window.updateLayoutAfterWfBusSave(result, true);
	
	if(success){
		document.forms[0].id.value = result.task.masterEntityKey;
	}
}

function createDoc(){
  
  var win = new Ext.ux.wf.WfSelRedHeadFile({
  });
  win.show();
}

//生成编号
function createCode() {
  var win = new Ext.ux.wf.CreateNoWin({
    template:'2',
    title:'选择发文编号'
  });
  win.on('complete', function(codeCmp){
    var field = document.getElementById('code');
    var value = codeCmp.getValue();
    var label = codeCmp.getRawValue();
    field.value = label;
  }, this);
  win.show();
}

function wfBusSave(templateCode){
	  if(validateForm()){
		    $('form[0]').attr('action', '${ctx}/oa-fawen!wfBusSave.action?templateCode='+ templateCode);
		    $('form[0]').submit();
	  }
}

function validateForm(){
	  if(document.forms[0].title.value == ''){
		    alert('标题不能为空，请填写!');
		    document.forms[0].title.focus();
		    return false;
	  }
	  return true;
}

function addMainSendOrgs(){
	var win = new Ext.ux.wf.SendOrgSelectWin({
		title: '添加主送机关'
	});
	win.on('complete', function(value){
		var field = document.getElementById('OaFawen_mainSend2');
		field.value = field.value == '' ? value : (field.value+'、'+value);
	}, this);
	win.show();
}

function addApposeSendOrgs(){
	var win = new Ext.ux.wf.SendOrgSelectWin({
		title: '添加抄送机关'
	});
	win.on('complete', function(value){
		var field = document.getElementById('OaFawen_apposeSend2');
		field.value = field.value == '' ? value : (field.value+'、'+value);
	}, this);
	win.show();
}

/**
 * 格式化 LABEL 对齐方式，把两个或者三个汉字与四个汉字对齐
 */
function formatLabelAlignment() {
    Ext.each(Ext.DomQuery.select("span[group=label]"), function(obj) {
        //obj.style.backgroundColor='red';
        var txt = obj.innerHTML
        var txts = txt.split("");
        // 超出四个汉字不格式化
        if (txts.length >= 4) return;
        
        var spanWidthIntValue = 64; // 12px大小的字体换成 48, 14px大小的字体换成56
        var ispanWidth = parseInt(spanWidthIntValue/txts.length);
        var ispanSuffWidth = spanWidthIntValue - ispanWidth * 3;
        
        obj.style.width = spanWidthIntValue;
        var thtml = '';
        for (var i = 0; i < txts.length; i++) {
            if (txts.length == 3 && i == txts.length - 1) ispanWidth += ispanSuffWidth;
            var alignTxt = (i == 0) ? 'left' : (i == txts.length - 1 ? 'right' : 'center');
            thtml += '<span style="width:' + ispanWidth + ';text-align:' + alignTxt + ';">' + txts[i] + '</span>';
        }
        obj.innerHTML = thtml;
    });
}

var editDocument = function(sysFileId){
    openCenterWindow(ctx + '/wf/wf-attachment-mgmt!addOrEditZhengwen.action?sysFileId='+sysFileId, 1050, 650);
}

function fileRegister() {
    Ext.Ajax.request({
        url: ctx + '/oa-fawen-register!save.action',
        params:{
          docCode: $('#OaFawen_code2').val(),
          docTitle: $('#OaFawen_title2').val(),
          sendTo: $('#OaFawen_mainSend2').val() + '、' + $('#OaFawen_apposeSend2').val(),
          type: 'fawen'
        },
        success:function(response){
          Ext.MessageBox.alert('系统提示','已将本发文登记到发文登记薄中！');
        }
    });
}

/*
function wfSendToPrevTask(taskInstDbid,templateCode){
  
    if(taskInstDbid != null){
      Ext.Ajax.request({
        url: ctx + '/wf/wf!wfSend.action',
        params:{
          'instance.taskInstDbid': taskInstDbid
        },
        success:function(response){
          var jsonText = response.responseText;
          var jsonObj = Ext.decode(jsonText);
          
          if(jsonObj.success){
            var win = new Ext.ux.wf.WfSendSuccessWin({
              templateCode: templateCode,
              message: jsonObj.errMsg
            });
            win.show();   
          }
        },
        failure:function(){
          Ext.Msg.alert('错误','发送失败');
        },
        scope: this
      });
    }else
      alert('提示：请点击“暂存”按钮保存业务数据并启动流程实例！');
};
*/

Ext.onReady(function () {
    // 格式化LABEL对齐
    formatLabelAlignment();
    
    var centerTabPanel = Ext.getCmp('centerTabPanel');
    //if(centerTabPanel){
    /**
	    var wfAttachMgmt = new Ext.ux.wf.WfAttachMgmt({
			    width           : 788,
			    height          : 250,
			    deferredRender  : false,
			    enableTabScroll : true,
			    title           : '正文或附件',
			    autoScroll      : true,
			    masterEntity   	: WF_CONFIG.masterEntity,
			    masterEntityKey	: WF_CONFIG.masterEntityKey,
			    busType			: 'OaFawen'
	    });
	    wfAttachMgmt.render('tpanelDiv');
	*/
	   
    //}
});

//归档
function wfArchive(){
	var docNameField = document.getElementById('OaFawen_title2');	
	var archiveWin = new Ext.ux.doc.DocArchiveWin({docName:docNameField.value});
	archiveWin.show();	
}
</script>